package com.xm.linxiaogang.network.converter

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.serializer.SerializeConfig
import okhttp3.MediaType
import okhttp3.RequestBody
import retrofit2.Converter
import java.io.IOException

/**
 * 重构请求体，指定请求数据的MediaType类型
 */
class FastJsonRequestBodyConverter<T>(private val serializeConfig: SerializeConfig) :
    Converter<T, RequestBody> {

    private val mediaType = MediaType.parse("application/json; charset=UTF-8")

    @Throws(IOException::class)
    override fun convert(value: T): RequestBody {
        return RequestBody.create(mediaType, JSON.toJSONBytes(value, serializeConfig))
    }

}